package cn.sc.summer.token.handler.server;

import cn.sc.summer.token.util.ResponseUtil;
import cn.sc.summer.constant.model.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;

/**
 * 类名：无权限处理类
 *
 * @author a-xin
 * @date 2024/8/19 16:22
 */
@Slf4j
public class AccessDeniedHandlerX implements AccessDeniedHandler {
    @Override
    public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException {
        accessDeniedException.printStackTrace();
        ResponseUtil.writeFailed(response, new HashMap<>(), Result.fail("No permissions: " + accessDeniedException.getMessage()));
    }
}
